package com.example.xianji.adapter;

import java.util.ArrayList;

import com.example.xianji.activity.Main_ZhanNei_DetailsActivity;
import com.example.xianji.R;
import com.example.xianji.bean.My_DuiJie;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ZhanNei_Adapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<My_DuiJie> list;


    public ZhanNei_Adapter(Context mContext, ArrayList<My_DuiJie> list) {
        super();
        this.mContext = mContext;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder mHolder;
        if (convertView == null) {
            mHolder = new Holder();
            convertView = View.inflate(mContext, R.layout.zhannei_listview_item, null);

            mHolder.textview_zhannei_time = (TextView) convertView.findViewById(R.id.textview_zhannei_time);
            mHolder.zhannei_title = (TextView) convertView.findViewById(R.id.zhannei_title);

            convertView.setTag(mHolder);
        }

        mHolder = (Holder) convertView.getTag();

        mHolder.textview_zhannei_time.setText(list.get(position).getCreated_at().substring(0, 10));
        mHolder.zhannei_title.setText(list.get(position).getTitle());
        final int a = position;
        convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, Main_ZhanNei_DetailsActivity.class);
                intent.putExtra("zhannei_id", list.get(a).getId());
                mContext.startActivity(intent);
            }
        });

        return convertView;
    }

    class Holder {
        TextView textview_zhannei_time;
        TextView zhannei_title;

    }

}
